<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>

			<% if(session.getAttribute("id")==null)
        	{
        		String boodschap = "You need to login first.";
        		response.sendRedirect("login.jsp?boodschap=" + boodschap + "&url=" + "main.jsp");
        	}
	%> 	

	


<form name="timer"  action="/main" method="post">
  		Duration of the current activity: <input id="duration" type="text" size="12" name="duration">
    	<input type="submit"  value="stop Timer" />
    	
    	<input type="hidden" name="userId" value="<%= session.getAttribute("id") %>" />
    	<input type="hidden" name="pauseDuration" id="pauseDuration" value="" />
</form>

<input id="pauseButton" type="submit" value="pause Timer" onclick="pause()" />
	
	<script type="text/javascript">
	var pauseTime=0;
	var seconds = 0;
	var minutes = 0;
	var hours = 0;
	var t;
	var p;
	var timer_is_on=0;

	function timedCount()
	{
		clearTimeout(p);
		var time = hours + ":" + minutes + ":" + seconds;
		document.getElementById("duration").value=time;
		 
		seconds = seconds + 1;
		if(seconds >= 60) {
			seconds = 0;
			minutes = minutes + 1;
		}
		if(minutes >= 60) {
			minutes = 0;
			hours = hours + 1;
		}
		
		t=setTimeout("timedCount()",1000);
	}
	
	timedCount();
	
	function pause() {
		if(timer_is_on == 0) {
			clearTimeout(t);
			timer_is_on=1;
			document.getElementById("pauseButton").value="herstart Timer";
			startPauseTimer();
		}
		else {
			clearTimeout(p);
			timer_is_on=0;
			document.getElementById("pauseButton").value="pause Timer";
			timedCount();
		}
		
	}
	
	function startPauseTimer() {
		pauseTime = pauseTime + 1;
		document.getElementById("pauseDuration").value= pauseTime;
		p = setTimeout("startPauseTimer()",100);
	}
	</script>
		
	

</body>
</html>